class Player(object):
    numbers = 0

    def __init__(self, name, age, city):
        self.name = name
        self.age = age
        self.city = city
        Player.numbers += 1


mia = Player('mia', 19, '北京')
mia.city = '杭州'  # 可以修改值
print(mia.__dict__)  # 获取（实例）对象的所有属性
print(f"欢迎梦幻世界第 {Player.numbers} 个玩家注册账号！")
tom = Player('tom', 20, '上海')
tom.height = 170  # 可以新增对象的特殊属性
print(tom.__dict__)
print(f"欢迎梦幻世界第 {Player.numbers} 个玩家注册账号！")


# 武器：名字  等级  攻击值
class Weapon(object):
    numbers = 0
    max_damage = 10000
    levels = ['青铜', '白银', '钻石', '王者', '黄金', '铂金']

    def __init__(self, name, level, damage):
        self.name = name
        self.level = level
        self.damage = damage
        if damage > Weapon.max_damage:
            raise Exception("最大伤害值是10000，请重试！")
        if level not in Weapon.levels:
            raise Exception("段位设置错误！")


try:
    gun = Weapon('MagicGun', '黄金', 1000)
    print(gun.__dict__)
    arrow = Weapon('arrow', '王者', 2000)
    print(arrow.__dict__)
except Exception as e:
    print(e)
